﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using SaleManagement.Domains;
using SaleManagement.Data;

#endregion

namespace SaleManagement.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="PurchaseProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class PurchaseProviderBaseCore : EntityProviderBase<SaleManagement.Domains.Purchase, SaleManagement.Domains.PurchaseKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, SaleManagement.Domains.PurchaseKey key)
		{
			return Delete(transactionManager, key.Id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _id)
		{
			return Delete(null, _id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _id);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		FK_tblPurchase_tblCustomer Description: 
		/// </summary>
		/// <param name="_customerId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		public TList<Purchase> GetByCustomerId(System.Int32 _customerId)
		{
			int count = -1;
			return GetByCustomerId(_customerId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		FK_tblPurchase_tblCustomer Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_customerId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		/// <remarks></remarks>
		public TList<Purchase> GetByCustomerId(TransactionManager transactionManager, System.Int32 _customerId)
		{
			int count = -1;
			return GetByCustomerId(transactionManager, _customerId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		FK_tblPurchase_tblCustomer Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_customerId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		public TList<Purchase> GetByCustomerId(TransactionManager transactionManager, System.Int32 _customerId, int start, int pageLength)
		{
			int count = -1;
			return GetByCustomerId(transactionManager, _customerId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		fkTblPurchaseTblCustomer Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_customerId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		public TList<Purchase> GetByCustomerId(System.Int32 _customerId, int start, int pageLength)
		{
			int count =  -1;
			return GetByCustomerId(null, _customerId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		fkTblPurchaseTblCustomer Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_customerId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		public TList<Purchase> GetByCustomerId(System.Int32 _customerId, int start, int pageLength,out int count)
		{
			return GetByCustomerId(null, _customerId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblPurchase_tblCustomer key.
		///		FK_tblPurchase_tblCustomer Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_customerId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Purchase objects.</returns>
		public abstract TList<Purchase> GetByCustomerId(TransactionManager transactionManager, System.Int32 _customerId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override SaleManagement.Domains.Purchase Get(TransactionManager transactionManager, SaleManagement.Domains.PurchaseKey key, int start, int pageLength)
		{
			return GetById(transactionManager, key.Id, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tblPurchase index.
		/// </summary>
		/// <param name="_id"></param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetById(System.Int32 _id)
		{
			int count = -1;
			return GetById(null,_id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblPurchase index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetById(System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(null, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblPurchase index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetById(TransactionManager transactionManager, System.Int32 _id)
		{
			int count = -1;
			return GetById(transactionManager, _id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblPurchase index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(transactionManager, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblPurchase index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetById(System.Int32 _id, int start, int pageLength, out int count)
		{
			return GetById(null, _id, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblPurchase index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public abstract SaleManagement.Domains.Purchase GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="_refNo"></param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetByRefNo(System.String _refNo)
		{
			int count = -1;
			return GetByRefNo(null,_refNo, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="_refNo"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetByRefNo(System.String _refNo, int start, int pageLength)
		{
			int count = -1;
			return GetByRefNo(null, _refNo, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_refNo"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetByRefNo(TransactionManager transactionManager, System.String _refNo)
		{
			int count = -1;
			return GetByRefNo(transactionManager, _refNo, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_refNo"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetByRefNo(TransactionManager transactionManager, System.String _refNo, int start, int pageLength)
		{
			int count = -1;
			return GetByRefNo(transactionManager, _refNo, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="_refNo"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public SaleManagement.Domains.Purchase GetByRefNo(System.String _refNo, int start, int pageLength, out int count)
		{
			return GetByRefNo(null, _refNo, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the UQ_tblPurchase_RefNo index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_refNo"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Purchase"/> class.</returns>
		public abstract SaleManagement.Domains.Purchase GetByRefNo(TransactionManager transactionManager, System.String _refNo, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _tblPurchase_GetByCustomer 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(System.Int32? customerId)
		{
			return GetByCustomer(null, 0, int.MaxValue , customerId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(int start, int pageLength, System.Int32? customerId)
		{
			return GetByCustomer(null, start, pageLength , customerId);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(TransactionManager transactionManager, System.Int32? customerId)
		{
			return GetByCustomer(transactionManager, 0, int.MaxValue , customerId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetByCustomer(TransactionManager transactionManager, int start, int pageLength , System.Int32? customerId);
		
		#endregion
		
		#region _tblPurchase_GetInputOutPutReport 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetInputOutPutReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetInputOutPutReport(System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetInputOutPutReport(null, 0, int.MaxValue , fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetInputOutPutReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetInputOutPutReport(int start, int pageLength, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetInputOutPutReport(null, start, pageLength , fromDate, toDate);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_GetInputOutPutReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetInputOutPutReport(TransactionManager transactionManager, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetInputOutPutReport(transactionManager, 0, int.MaxValue , fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetInputOutPutReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetInputOutPutReport(TransactionManager transactionManager, int start, int pageLength , System.DateTime? fromDate, System.DateTime? toDate);
		
		#endregion
		
		#region _tblPurchase_CreateTempTbl 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_CreateTempTbl' stored procedure. 
		/// </summary>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CreateTempTbl()
		{
			 CreateTempTbl(null, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_CreateTempTbl' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CreateTempTbl(int start, int pageLength)
		{
			 CreateTempTbl(null, start, pageLength );
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_CreateTempTbl' stored procedure. 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CreateTempTbl(TransactionManager transactionManager)
		{
			 CreateTempTbl(transactionManager, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_CreateTempTbl' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void CreateTempTbl(TransactionManager transactionManager, int start, int pageLength );
		
		#endregion
		
		#region _tblPurchase_TransferFromTemp 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_TransferFromTemp' stored procedure. 
		/// </summary>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void TransferFromTemp()
		{
			 TransferFromTemp(null, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_TransferFromTemp' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void TransferFromTemp(int start, int pageLength)
		{
			 TransferFromTemp(null, start, pageLength );
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_TransferFromTemp' stored procedure. 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void TransferFromTemp(TransactionManager transactionManager)
		{
			 TransferFromTemp(transactionManager, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_TransferFromTemp' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void TransferFromTemp(TransactionManager transactionManager, int start, int pageLength );
		
		#endregion
		
		#region _tblPurchase_GetPurchaseReport 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetPurchaseReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetPurchaseReport(System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetPurchaseReport(null, 0, int.MaxValue , fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetPurchaseReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetPurchaseReport(int start, int pageLength, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetPurchaseReport(null, start, pageLength , fromDate, toDate);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_GetPurchaseReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetPurchaseReport(TransactionManager transactionManager, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return GetPurchaseReport(transactionManager, 0, int.MaxValue , fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_GetPurchaseReport' stored procedure. 
		/// </summary>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetPurchaseReport(TransactionManager transactionManager, int start, int pageLength , System.DateTime? fromDate, System.DateTime? toDate);
		
		#endregion
		
		#region _tblPurchase_Reject 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Reject' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Reject(System.Int32? purchaseId)
		{
			 Reject(null, 0, int.MaxValue , purchaseId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Reject' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Reject(int start, int pageLength, System.Int32? purchaseId)
		{
			 Reject(null, start, pageLength , purchaseId);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_Reject' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Reject(TransactionManager transactionManager, System.Int32? purchaseId)
		{
			 Reject(transactionManager, 0, int.MaxValue , purchaseId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Reject' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void Reject(TransactionManager transactionManager, int start, int pageLength , System.Int32? purchaseId);
		
		#endregion
		
		#region _tblPurchase_Search 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Search' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="purchaseCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Search(System.String customerCode, System.String customerName, System.String customerPhone, System.String purchaseCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return Search(null, 0, int.MaxValue , customerCode, customerName, customerPhone, purchaseCode, fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Search' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="purchaseCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Search(int start, int pageLength, System.String customerCode, System.String customerName, System.String customerPhone, System.String purchaseCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return Search(null, start, pageLength , customerCode, customerName, customerPhone, purchaseCode, fromDate, toDate);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_Search' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="purchaseCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Search(TransactionManager transactionManager, System.String customerCode, System.String customerName, System.String customerPhone, System.String purchaseCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return Search(transactionManager, 0, int.MaxValue , customerCode, customerName, customerPhone, purchaseCode, fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Search' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="purchaseCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet Search(TransactionManager transactionManager, int start, int pageLength , System.String customerCode, System.String customerName, System.String customerPhone, System.String purchaseCode, System.DateTime? fromDate, System.DateTime? toDate);
		
		#endregion
		
		#region _tblPurchase_Approve 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Approve' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Approve(System.Int32? purchaseId)
		{
			 Approve(null, 0, int.MaxValue , purchaseId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Approve' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Approve(int start, int pageLength, System.Int32? purchaseId)
		{
			 Approve(null, start, pageLength , purchaseId);
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_Approve' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Approve(TransactionManager transactionManager, System.Int32? purchaseId)
		{
			 Approve(transactionManager, 0, int.MaxValue , purchaseId);
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_Approve' stored procedure. 
		/// </summary>
		/// <param name="purchaseId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void Approve(TransactionManager transactionManager, int start, int pageLength , System.Int32? purchaseId);
		
		#endregion
		
		#region _tblPurchase_DeleteTempTbl 
		
		/// <summary>
		///	This method wrap the '_tblPurchase_DeleteTempTbl' stored procedure. 
		/// </summary>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void DeleteTempTbl()
		{
			 DeleteTempTbl(null, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_DeleteTempTbl' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void DeleteTempTbl(int start, int pageLength)
		{
			 DeleteTempTbl(null, start, pageLength );
		}
				
		/// <summary>
		///	This method wrap the '_tblPurchase_DeleteTempTbl' stored procedure. 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void DeleteTempTbl(TransactionManager transactionManager)
		{
			 DeleteTempTbl(transactionManager, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_tblPurchase_DeleteTempTbl' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void DeleteTempTbl(TransactionManager transactionManager, int start, int pageLength );
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Purchase&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Purchase&gt;"/></returns>
		public static TList<Purchase> Fill(IDataReader reader, TList<Purchase> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				SaleManagement.Domains.Purchase c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Purchase")
					.Append("|").Append((System.Int32)reader[((int)PurchaseColumn.Id - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Purchase>(
					key.ToString(), // EntityTrackingKey
					"Purchase",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new SaleManagement.Domains.Purchase();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Id = (System.Int32)reader[((int)PurchaseColumn.Id - 1)];
					c.RepositoryId = (System.Int32)reader[((int)PurchaseColumn.RepositoryId - 1)];
					c.RefNo = (System.String)reader[((int)PurchaseColumn.RefNo - 1)];
					c.CustomerId = (System.Int32)reader[((int)PurchaseColumn.CustomerId - 1)];
					c.Date = (System.DateTime)reader[((int)PurchaseColumn.Date - 1)];
					c.Total = (reader.IsDBNull(((int)PurchaseColumn.Total - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.Total - 1)];
					c.Commission = (reader.IsDBNull(((int)PurchaseColumn.Commission - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.Commission - 1)];
					c.RealTotal = (reader.IsDBNull(((int)PurchaseColumn.RealTotal - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.RealTotal - 1)];
					c.Notes = (reader.IsDBNull(((int)PurchaseColumn.Notes - 1)))?null:(System.String)reader[((int)PurchaseColumn.Notes - 1)];
					c.CreatedDate = (System.DateTime)reader[((int)PurchaseColumn.CreatedDate - 1)];
					c.CreatedBy = (System.String)reader[((int)PurchaseColumn.CreatedBy - 1)];
					c.UpdatedDate = (reader.IsDBNull(((int)PurchaseColumn.UpdatedDate - 1)))?null:(System.DateTime?)reader[((int)PurchaseColumn.UpdatedDate - 1)];
					c.UpdatedBy = (reader.IsDBNull(((int)PurchaseColumn.UpdatedBy - 1)))?null:(System.String)reader[((int)PurchaseColumn.UpdatedBy - 1)];
					c.RequiredModified = (reader.IsDBNull(((int)PurchaseColumn.RequiredModified - 1)))?null:(System.String)reader[((int)PurchaseColumn.RequiredModified - 1)];
					c.Status = (reader.IsDBNull(((int)PurchaseColumn.Status - 1)))?null:(System.String)reader[((int)PurchaseColumn.Status - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="SaleManagement.Domains.Purchase"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Purchase"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, SaleManagement.Domains.Purchase entity)
		{
			if (!reader.Read()) return;
			
			entity.Id = (System.Int32)reader[((int)PurchaseColumn.Id - 1)];
			entity.RepositoryId = (System.Int32)reader[((int)PurchaseColumn.RepositoryId - 1)];
			entity.RefNo = (System.String)reader[((int)PurchaseColumn.RefNo - 1)];
			entity.CustomerId = (System.Int32)reader[((int)PurchaseColumn.CustomerId - 1)];
			entity.Date = (System.DateTime)reader[((int)PurchaseColumn.Date - 1)];
			entity.Total = (reader.IsDBNull(((int)PurchaseColumn.Total - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.Total - 1)];
			entity.Commission = (reader.IsDBNull(((int)PurchaseColumn.Commission - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.Commission - 1)];
			entity.RealTotal = (reader.IsDBNull(((int)PurchaseColumn.RealTotal - 1)))?null:(System.Int32?)reader[((int)PurchaseColumn.RealTotal - 1)];
			entity.Notes = (reader.IsDBNull(((int)PurchaseColumn.Notes - 1)))?null:(System.String)reader[((int)PurchaseColumn.Notes - 1)];
			entity.CreatedDate = (System.DateTime)reader[((int)PurchaseColumn.CreatedDate - 1)];
			entity.CreatedBy = (System.String)reader[((int)PurchaseColumn.CreatedBy - 1)];
			entity.UpdatedDate = (reader.IsDBNull(((int)PurchaseColumn.UpdatedDate - 1)))?null:(System.DateTime?)reader[((int)PurchaseColumn.UpdatedDate - 1)];
			entity.UpdatedBy = (reader.IsDBNull(((int)PurchaseColumn.UpdatedBy - 1)))?null:(System.String)reader[((int)PurchaseColumn.UpdatedBy - 1)];
			entity.RequiredModified = (reader.IsDBNull(((int)PurchaseColumn.RequiredModified - 1)))?null:(System.String)reader[((int)PurchaseColumn.RequiredModified - 1)];
			entity.Status = (reader.IsDBNull(((int)PurchaseColumn.Status - 1)))?null:(System.String)reader[((int)PurchaseColumn.Status - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="SaleManagement.Domains.Purchase"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Purchase"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, SaleManagement.Domains.Purchase entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Id = (System.Int32)dataRow["Id"];
			entity.RepositoryId = (System.Int32)dataRow["RepositoryId"];
			entity.RefNo = (System.String)dataRow["RefNo"];
			entity.CustomerId = (System.Int32)dataRow["CustomerId"];
			entity.Date = (System.DateTime)dataRow["Date"];
			entity.Total = Convert.IsDBNull(dataRow["Total"]) ? null : (System.Int32?)dataRow["Total"];
			entity.Commission = Convert.IsDBNull(dataRow["Commission"]) ? null : (System.Int32?)dataRow["Commission"];
			entity.RealTotal = Convert.IsDBNull(dataRow["RealTotal"]) ? null : (System.Int32?)dataRow["RealTotal"];
			entity.Notes = Convert.IsDBNull(dataRow["Notes"]) ? null : (System.String)dataRow["Notes"];
			entity.CreatedDate = (System.DateTime)dataRow["CreatedDate"];
			entity.CreatedBy = (System.String)dataRow["CreatedBy"];
			entity.UpdatedDate = Convert.IsDBNull(dataRow["UpdatedDate"]) ? null : (System.DateTime?)dataRow["UpdatedDate"];
			entity.UpdatedBy = Convert.IsDBNull(dataRow["UpdatedBy"]) ? null : (System.String)dataRow["UpdatedBy"];
			entity.RequiredModified = Convert.IsDBNull(dataRow["RequiredModified"]) ? null : (System.String)dataRow["RequiredModified"];
			entity.Status = Convert.IsDBNull(dataRow["Status"]) ? null : (System.String)dataRow["Status"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Purchase"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">SaleManagement.Domains.Purchase Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, SaleManagement.Domains.Purchase entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region CustomerIdSource	
			if (CanDeepLoad(entity, "Customer|CustomerIdSource", deepLoadType, innerList) 
				&& entity.CustomerIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.CustomerId;
				Customer tmpEntity = EntityManager.LocateEntity<Customer>(EntityLocator.ConstructKeyFromPkItems(typeof(Customer), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CustomerIdSource = tmpEntity;
				else
					entity.CustomerIdSource = DataRepository.CustomerProvider.GetById(transactionManager, entity.CustomerId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CustomerIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CustomerIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CustomerProvider.DeepLoad(transactionManager, entity.CustomerIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CustomerIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetById methods when available
			
			#region PaymentDetailCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PaymentDetail>|PaymentDetailCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PaymentDetailCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PaymentDetailCollection = DataRepository.PaymentDetailProvider.GetByPurchaseId(transactionManager, entity.Id);

				if (deep && entity.PaymentDetailCollection.Count > 0)
				{
					deepHandles.Add("PaymentDetailCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PaymentDetail>) DataRepository.PaymentDetailProvider.DeepLoad,
						new object[] { transactionManager, entity.PaymentDetailCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PurchaseDetailCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PurchaseDetail>|PurchaseDetailCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PurchaseDetailCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PurchaseDetailCollection = DataRepository.PurchaseDetailProvider.GetByPurchaseId(transactionManager, entity.Id);

				if (deep && entity.PurchaseDetailCollection.Count > 0)
				{
					deepHandles.Add("PurchaseDetailCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PurchaseDetail>) DataRepository.PurchaseDetailProvider.DeepLoad,
						new object[] { transactionManager, entity.PurchaseDetailCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the SaleManagement.Domains.Purchase object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">SaleManagement.Domains.Purchase instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">SaleManagement.Domains.Purchase Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, SaleManagement.Domains.Purchase entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region CustomerIdSource
			if (CanDeepSave(entity, "Customer|CustomerIdSource", deepSaveType, innerList) 
				&& entity.CustomerIdSource != null)
			{
				DataRepository.CustomerProvider.Save(transactionManager, entity.CustomerIdSource);
				entity.CustomerId = entity.CustomerIdSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
	
			#region List<PaymentDetail>
				if (CanDeepSave(entity.PaymentDetailCollection, "List<PaymentDetail>|PaymentDetailCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PaymentDetail child in entity.PaymentDetailCollection)
					{
						if(child.PurchaseIdSource != null)
						{
							child.PurchaseId = child.PurchaseIdSource.Id;
						}
						else
						{
							child.PurchaseId = entity.Id;
						}

					}

					if (entity.PaymentDetailCollection.Count > 0 || entity.PaymentDetailCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PaymentDetailProvider.Save(transactionManager, entity.PaymentDetailCollection);
						
						deepHandles.Add("PaymentDetailCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PaymentDetail >) DataRepository.PaymentDetailProvider.DeepSave,
							new object[] { transactionManager, entity.PaymentDetailCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PurchaseDetail>
				if (CanDeepSave(entity.PurchaseDetailCollection, "List<PurchaseDetail>|PurchaseDetailCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PurchaseDetail child in entity.PurchaseDetailCollection)
					{
						if(child.PurchaseIdSource != null)
						{
							child.PurchaseId = child.PurchaseIdSource.Id;
						}
						else
						{
							child.PurchaseId = entity.Id;
						}

					}

					if (entity.PurchaseDetailCollection.Count > 0 || entity.PurchaseDetailCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PurchaseDetailProvider.Save(transactionManager, entity.PurchaseDetailCollection);
						
						deepHandles.Add("PurchaseDetailCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PurchaseDetail >) DataRepository.PurchaseDetailProvider.DeepSave,
							new object[] { transactionManager, entity.PurchaseDetailCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region PurchaseChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>SaleManagement.Domains.Purchase</c>
	///</summary>
	public enum PurchaseChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Customer</c> at CustomerIdSource
		///</summary>
		[ChildEntityType(typeof(Customer))]
		Customer,
	
		///<summary>
		/// Collection of <c>Purchase</c> as OneToMany for PaymentDetailCollection
		///</summary>
		[ChildEntityType(typeof(TList<PaymentDetail>))]
		PaymentDetailCollection,

		///<summary>
		/// Collection of <c>Purchase</c> as OneToMany for PurchaseDetailCollection
		///</summary>
		[ChildEntityType(typeof(TList<PurchaseDetail>))]
		PurchaseDetailCollection,
	}
	
	#endregion PurchaseChildEntityTypes
	
	#region PurchaseFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;PurchaseColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Purchase"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PurchaseFilterBuilder : SqlFilterBuilder<PurchaseColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PurchaseFilterBuilder class.
		/// </summary>
		public PurchaseFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PurchaseFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PurchaseFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PurchaseFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PurchaseFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PurchaseFilterBuilder
	
	#region PurchaseParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;PurchaseColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Purchase"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PurchaseParameterBuilder : ParameterizedSqlFilterBuilder<PurchaseColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PurchaseParameterBuilder class.
		/// </summary>
		public PurchaseParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PurchaseParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PurchaseParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PurchaseParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PurchaseParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PurchaseParameterBuilder
	
	#region PurchaseSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;PurchaseColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Purchase"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class PurchaseSortBuilder : SqlSortBuilder<PurchaseColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PurchaseSqlSortBuilder class.
		/// </summary>
		public PurchaseSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion PurchaseSortBuilder
	
} // end namespace
